const recorderManager = my.getRecorderManager()
let that = null;
recorderManager.onStart(() => {
  console.log('recorder start')
})
recorderManager.onStop((res) => {
  console.log('recorder end', res.tempFilePath)
  that.setData({
    src: res.tempFilePath
  })
})
const nodes = [{
  "tag": "p",
  "attrs": [],
  "children": [
    "欢迎使用 ",
    {
      "tag": "b",
      "attrs": [
      { "name": "style", "value": "color:red;" }],
      "children": ['Hello&nbsp;World!']
    },
    " 富文本编辑器"
  ]
},
{
  "tag": "p",
  "attrs": [],
  "children": [
    {
      "tag": "p",
      "attrs": [
        { "name": "p", "value": "color:red;" },
        { "name": "style", "value": "color:red;" }
      ]
    }
  ]
}];

Page({
  data: {
    src: "",
    nodes: [

    ],
  },
  onLoad() {
    let a = this.fn(nodes)
    this.setData({
      nodes: a
    })
  },

  cfn(item) {
    item.name = item.tag;
    delete item.tag;
    if (item.attrs) {
      
      let tempattrs = {}
      item.attrs.map((v) => {
        tempattrs[v.name] = v.value
      });
      
      item.attrs = tempattrs
    }
    if (item.children) {
      item.children = this.fn(item.children)
    }

    return item
  },

  fn(targetData) {
    let newDate = targetData.map(item => {
      return Object.prototype.toString.call(item) === "[object Object]" ? this.cfn(item) : { type: 'text', text: item }

      // if (Object.prototype.toString.call(item) === "[object Object]") {
      //   item.name = item.tag;
      //   delete item.tag;
      //   if (item.attrs) {
      //     let tempattrs = {}
      //     item.attrs.map((v) => {
      //       // console.log(v.name ,v.value);
      //       tempattrs[v.name] = v.value
      //     });
      //     item.attrs = tempattrs
      //   }
      //   if (item.children) {
      //     this.fn(item.children)
      //   }
      // }else{
      //   item = {type:'text',text:item}
      //   return item
      // }
      // // return item
    });
    console.log(newDate, '00000targetData')
    return newDate

  }

});


